#pragma once

class WMOModel : public ModelBase
{
	CMpqFile* m_file;
	std::string m_fileName;
	ui32 LoadChunk(ui32& sig, ui32& len);
	WMOHeader m_header;
	std::map<ui32, std::string> m_textures;
	std::vector<WMOMaterial> m_materials;
	std::vector<Texture*> m_texids;
	std::vector<std::string> m_groupnames;
	std::vector<WMOGroupInfo> m_groupinfos;
	std::vector<WMOLight> m_lights;
	std::vector<WMODoodadSet> m_sets;
	std::map<ui32, std::string> m_doodads;
	std::vector<WMODoodadInfo> m_doodadinfos;
	std::vector<WMOGroup*> m_groups;

	void LoadTextures(ui32 size);
	void LoadMaterials();
	void LoadGroupNames(ui32 size);
	void LoadGroupInfo();
	void LoadLights();
	void LoadSets();
	void LoadDoodads(ui32 size);
	void LoadDoodadInfos();

	float m_translation[3];
	float m_rotation[3];

	MODF m_spawnInfo;

	ui32 m_lastUpdate;
public:
	WMOModel(std::string szWmo, MODF mf);
	bool Init();
	void Draw(Vertex3F pos, Vertex3F tar);
	Texture* GetTexture(ui32 index)
	{
		if(index > m_texids.size())
			return 0;
		return m_texids[index];
	}
	void SetTranslation(float x, float y, float z)
	{
		m_translation[0] = x;
		m_translation[1] = y;
		m_translation[2] = z;
	}

	void SetRotation(float x, float y, float z)
	{
		m_rotation[0] = x;
		m_rotation[1] = y;
		m_rotation[2] = z;
	}

	void Save()
	{
		for(ui32 i = 0; i < m_groups.size(); ++i)
			m_groups[i]->Save();
	}
};